/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package stm_database;

import java.util.Comparator;
/**
 *
 * @author Honza
 */
public class DatabaseItemComparator implements Comparator<DatabaseItem>{
    /**
     * podle jakeho indexu se tridi
     */
    protected int database_item_index;
    /**
     * jestli je jiz setrizeno
     */
    protected boolean sort_order;
    public DatabaseItemComparator()
    {
        
    }
    public DatabaseItemComparator(int i, boolean order)
    {
        database_item_index = i;
        sort_order = order;
    }
    /**
     * porovnani podle stringu, jenom u id = 1 se porovnava podle intu
     * @param i1
     * @param i2
     * @return 
     */
    @Override public int compare(DatabaseItem i1, DatabaseItem i2)
    {
        int result = 0;
        if(database_item_index == 0)//radi se podle cisla id
        {
            
            
            result = new Integer(Integer.parseInt(i1.get(database_item_index))).compareTo
                    (new Integer(Integer.parseInt(i2.get(database_item_index))));
        }else
        {
            result = i1.get(database_item_index).compareTo(i2.get(database_item_index));
        }
        
        if(sort_order)
            return result;            
        else 
           return -1 * result; 
    }
    
    
}
